package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.entity.ActionTypeEnum;
import com.igoal.entity.ComponentEnum;
import com.igoal.entity.WallPlace;
import com.igoal.entity.WallSetting;

@Repository("wallSettingDAO")
public class WallSettingDAOImpl extends GenericDaoHibernate<WallSetting, Long> implements WallSettingDAO {

	public WallSettingDAOImpl() {
		super(WallSetting.class);
	}

	private WallSetting getSetting(ComponentEnum component, ActionTypeEnum action) {
		DetachedCriteria dc = DetachedCriteria.forClass(WallSetting.class);
		dc.add(Restrictions.eq("component", component));
		dc.add(Restrictions.eq("action", action));
		List<WallSetting> result = findByCriteria(dc);
		if (result != null && result.size() > 0) {
			return result.get(0);
		}
		return null;
	}

	public boolean showOnWall(ComponentEnum component, ActionTypeEnum action) {
		WallSetting ws = getSetting(component, action);
		return ws != null;
	}

	public WallPlace getLikeAndCommentComponent(ComponentEnum component, ActionTypeEnum action) {
		WallSetting ws = getSetting(component, action);
		if (ws != null) {
			return ws.getPlace();
		}
		return null;
	}

}
